import json

filename = "favorite_number.json"
favorite_number = input("请输入你喜欢的数字：")
try:
    with open(filename, 'w') as file_object:
        json.dump(int(favorite_number), file_object)
except ValueError:
    print("你输入的不是有效的数字哦，请重新输入。")